package net.awpspace.walkman.utils;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;

import net.awpspace.walkman.entity.MP3;
import net.awpspace.walkman.entity.Tag;

/**
 * Library loader
 * 
 * @author Diep AwpSpace
 * 
 */
public class Loader {

	public static final String FILE_PATH = "file:///E:/Nhac";

	public static Vector musics;

	public static void updateLibrary() {
		if (musics == null) {
			musics = new Vector();
		}
		musics.removeAllElements();
		try {
			FileConnection localdir = (FileConnection) Connector.open(
					FILE_PATH, Connector.READ_WRITE);
			if (localdir.exists()) {
				Enumeration list = localdir.list();
				while (list.hasMoreElements()) {
					String filePath = FILE_PATH + "/"
							+ (String) list.nextElement();
					Tag tag = new Tag(filePath);
					tag.Read();
					musics.addElement(new MP3(-1, filePath, tag.getTitile(),
							tag.getArtist(), tag.getAlbum()));
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
